package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftWarning;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/20
 *
 * 塔吊预警
 */

public class LiftWarningListAdapter extends RecyclerAdapter<LiftWarning, LiftWarningListAdapter.liftWarningListViewHolder> {

    public LiftWarningListAdapter(Context context, List<LiftWarning> dataList) {
        super(context, dataList);
    }

    @Override
    public liftWarningListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_lift_warning, null);
        return new liftWarningListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(liftWarningListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class liftWarningListViewHolder extends RecyclerAdapter.BaseViewHolder<LiftWarning>{
        @BindView(R.id.lift_name_tv)
        HXTextView liftNameTv;
        @BindView(R.id.lift_type_tv)
        HXTextView liftTypeTv;
        @BindView(R.id.lift_value_tv)
        HXTextView liftValueTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public liftWarningListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LiftWarning liftWarning = dataList.get(position);
            liftNameTv.setText(liftWarning.getEquipmentName() + "\t" + liftWarning.getNumber());
            if(liftWarning.getType().equals("预警")){
                liftTypeTv.setEnabled(true);
                liftTypeTv.setText("预警");
            }else {
                liftTypeTv.setEnabled(false);
                liftTypeTv.setText("报警");
            }
            liftValueTv.setText(liftWarning.getContent() + "\t" + liftWarning.getValue());
            createTimeTv.setText(liftWarning.getAcquisitionTime());
        }
    }
}
